<template>
  <div class="modal-column">
    <div class="modal-column-full-body">
      <Form ref="form" :model="model" :rules="validationRules" :labelWidth="120">
        <FormItem label="名称" required prop="name">
          <Input placeholder="请输入名称" v-model="model.name"/>
        </FormItem>
        <FormItem label="编码" prop="code">
          <Input :readonly="model.id" placeholder="编码(不填系统自动生成)" v-model="model.code"/>
        </FormItem>
        <FormItem label="联系人姓名" required prop="linkman">
          <Input placeholder="请输入联系人姓名" v-model="model.linkman"/>
        </FormItem>
        <FormItem label="联系人电话" required prop="phone">
          <Input placeholder="请输入联系人电话" v-model="model.phone"/>
        </FormItem>
        <FormItem label="类型" prop="type">
          <Radio v-model="model.type" :datas="{0:'机构',1:'部门'}"></Radio>
        </FormItem>
        <FormItem label="地址" prop="address">
          <Input placeholder="请输入地址" v-model="model.address"/>
        </FormItem>
      </Form>
    </div>
    <div class="modal-column-between">
      <Button icon="fa fa-close" @click="$emit('close')" :loading="loading">
        取消
      </Button>
      <Button icon="fa fa-save" color="primary" @click="confirm" :loading="loading">
        保存
      </Button>
    </div>
  </div>
</template>

<script>
/**
 * @功能描述: 组织机构Form
 * @创建时间: 2023年08月08日
 * @公司官网: www.fenxi365.com
 * @公司信息: 纷析云（杭州）科技有限公司
 * @公司介绍: 专注于财务相关软件开发, 企业会计自动化解决方案
 */
import Organization from "@js/api/Organization";
import {message} from "heyui";
import {CopyObj} from "@common/utils";
export default {
  name: "OrganizationForm",
  emits: {
    close: null,
    success: null
  },
  props: {
    organization: Object,
    parent: Object,
  },
  data() {
    return {
      loading: false,
      merchantList: [],
      model: {
        id: null,
        address: null,
        code: null,
        merchantId: null,
        type: 0,
        email: null,
        linkman: null,
        name: null,
        phone: null,
      },
      validationRules: {
      }
    }
  },
  methods: {
    confirm() {
      let validResult = this.$refs.form.valid();
      if (validResult.result) {
        this.loading = true;
        Organization.save(this.model).then(() => {
          message("保存成功~");
          this.$emit('success');
        }).finally(() => this.loading = false);
      }
    },
    init() {
    }
  },
  created() {
    this.init();
    CopyObj(this.model, this.organization);
    if (this.parent) {
      this.model.parentId = this.parent.id;
    }
  }
}
</script>
